<%--
  Created by IntelliJ IDEA.
  User: ghp
  Date: 2022/8/17
  Time: 17:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎注册</title>
    <%--这里一定要记得加虚拟目录啊，因为这三给浏览器访问~~~~气死我了--%>
    <link href="/day12_LoginAndRegister/css/register.css" rel="stylesheet">
</head>
<body>

<div class="form-div">
    <div class="reg-content">
        <h1>页面注册</h1>
        <span>已有帐号？</span> <a href="/day12_LoginAndRegister/jsp/login.jsp">登录</a>
    </div>
    <form id="reg-form" action="http://localhost:8080/day12_LoginAndRegister/RegisterServlet" method="post">

        <table>

            <tr>
                <td>用户名</td>
                <td class="inputs">
                    <input name="username" type="text" id="username">
                    <br>
                    <span id="username_err" class="err_msg">${register_msg}</span>
                </td>

            </tr>

            <tr>
                <td>密码</td>
                <td class="inputs">
                    <input name="password" type="password" id="password">
                    <br>
                    <span id="password_err" class="err_msg" style="display: none">密码格式有误</span>
                </td>
            </tr>

            <tr>
                <td>验证码</td>
                <td class="inputs">
                    <input name="checkCode" type="text" id="checkCode">
                    <img src="/day12_LoginAndRegister/CheckCodeServlet" id="authImg"/>
                    <a href="#" id="changeImg">看不清？</a>
                </td>
            </tr>

        </table>

        <div class="buttons">
            <input value="注 册" type="submit" id="reg_btn">
        </div>
        <br class="clear">
    </form>

</div>
<script>
    //给字添加点击事件，每点击一次换一次验证码
    document.querySelector("#changeImg").onclick = function () {
        //因为src会被缓存，当两次修改的src地址一样，会导致点击事件不会让页面刷新，所以需要设置一个永远不相等的值
        // document.querySelector("authImg").src = "/day12_LoginAndRegister/CheckCodeServlet";
        document.querySelector("#authImg").src = "/day12_LoginAndRegister/CheckCodeServlet?" + new Date().getMilliseconds();
    }
    //给验证码添加点击事件，每点击一次换一次验证码
    document.querySelector("#authImg").onclick = function () {
        //因为src会被缓存，当两次修改的src地址一样，会导致点击事件不会让页面刷新，所以需要设置一个永远不相等的值
        // document.querySelector("authImg").src = "/day12_LoginAndRegister/CheckCodeServlet";
        document.querySelector("#authImg").src = "/day12_LoginAndRegister/CheckCodeServlet?" + new Date().getMilliseconds();
    }
</script>
</body>
</html>